package com.zry.yard.ui.activity


import android.content.Intent
import android.view.View
import com.zry.yard.R
import com.zry.yard.been.ResultBean
import com.zry.yard.been.StoreOrderBean
import com.zry.yard.been.StoreOrderInfo
import com.zry.yard.databinding.ActivityPutStorageRecordInfoBinding
import com.zry.yard.retrofit.HttpServer
import com.zry.yard.retrofit.ShowUserView
import com.zry.yard.ui.base.BaseActivity
import kotlinx.android.synthetic.main.activity_put_storage_record_info.*
import kotlinx.android.synthetic.main.common_title.*

class PutStorageRecordInfoActivity : BaseActivity(), ShowUserView {

    companion object {
        var putStorageRecordInfoActivity: PutStorageRecordInfoActivity? = null
    }

    private var putStorageRecordInfoBinding: ActivityPutStorageRecordInfoBinding? = null
    private var storeOrder: StoreOrderBean? = null
    override fun getLayoutId(): Int {
        return R.layout.activity_put_storage_record_info
    }

    override fun initData() {
        putStorageRecordInfoActivity = this
        storeOrder = intent.getSerializableExtra("storeOrderBean") as StoreOrderBean
        titleCenterText.text = "入库详情"
        commonLeftLinearLayout.setOnClickListener { finish() }

        putStorageRecordInfoBinding = viewDataBinding as ActivityPutStorageRecordInfoBinding
        putStorageRecordInfoBinding?.handlerClick = this

        HttpServer(this).getStoreOrderInfo(storeOrder!!.StoreOrderID, this)
    }

    fun knotOrderHandlerClick(view: View) {
        when (view.id) {
            R.id.knotOrderBtn -> {
                val intent = Intent(this, DialogActivity::class.java)
                intent.putExtra("orderID", storeOrder!!.StoreOrderID)
                startActivity(intent)
            }
        }
    }

    override fun toMainActivity(what: Int, data: Any) {
        when (what) {
            32 -> {
                try {
                    val resultData = data as ResultBean<StoreOrderInfo>
                    if (resultData.State == "1") {
                        putStorageRecordInfoBinding?.storeOrderInfo = resultData.ResultData
                        when (resultData.ResultData.StoreType) {
                            "1" -> putStorageTypeTV.text = "单品入库"
                            "2" -> putStorageTypeTV.text = "二级码入库"
                            "3" -> putStorageTypeTV.text = "三级码入库"
                        }
                        when (resultData.ResultData.StateID) {
                            "1" -> putStorageModeTV.text = "手动入库"
                            "2" -> putStorageModeTV.text = "自动入库"
                        }
                        productBrandNameTV.text = storeOrder!!.NetUnitPackName
                        when (resultData.ResultData.OrderState) {
                            "0" -> {
                                putStorageStateTV.text = "未结单"
                                knotOrderPutStorageLinear.visibility = View.VISIBLE
                            }
                            "1" -> {
                                putStorageStateTV.text = "已结单"
                            }
                        }
                    } else {
                        toast(resultData.Message)
                    }
                }catch (e:Exception){
                    e.printStackTrace()
                }

            }
        }
    }
}
